package com.lm.rdf4j.example;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.memory.MemoryStore;

public class Rdf4jFraudDetection {
    public static void main(String[] args) {
        // 创建内存存储库
        Repository repo = new SailRepository(new MemoryStore());
        repo.init();

        try (RepositoryConnection conn = repo.getConnection()) {
            // 创建 RDF 数据
            ValueFactory vf = SimpleValueFactory.getInstance();
            IRI user = vf.createIRI("http://example.com/user123");
            IRI transaction = vf.createIRI("http://example.com/tx001");
            IRI device = vf.createIRI("http://example.com/device456");
            IRI ip = vf.createIRI("http://example.com/ip789");

            // 添加 RDF 关系
            conn.add(user, vf.createIRI("http://example.com/madeTransaction"), transaction);
            conn.add(user, vf.createIRI("http://example.com/usedDevice"), device);
            conn.add(device, vf.createIRI("http://example.com/connectedFrom"), ip);
            conn.add(ip, vf.createIRI("http://example.com/flaggedAs"), vf.createLiteral("fraud"));

            System.out.println("RDF 数据已成功存入内存存储！");
        }

        repo.shutDown();
    }
}
